package com.cloud.sso.common.log;

import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by tyd on 2017-10-13.
 * @author tyd
 */
public class LogManager {


    /**
     * 日志延长记录时间
     */
    private static final Integer LOG_DELAY_TIME = 10;

    /**
     *   异步日志记录线程池
     */

    private ScheduledThreadPoolExecutor logExecutor = new ScheduledThreadPoolExecutor(10);

    /**
        使用单例模式获取LogManager对象 (使用双重检测锁方式)
     */
    private volatile static LogManager logManager;

    private LogManager() {
    }

    public static LogManager getLogManager() {
        if (logManager == null) {
            synchronized (LogManager.class) {
                if (logManager == null) {
                    logManager = new LogManager();
                }
            }
        }
        return logManager;
    }

    public void executeLog(TimerTask task) {
        logExecutor.schedule(task, LOG_DELAY_TIME, TimeUnit.MILLISECONDS);
    }


}
